package com.snailhd.scheduled;

import com.snailhd.crawler.CrawlerRealTimeStockDataExector;
import com.snailhd.dto.QueryStockListDTO;
import com.snailhd.entity.Stock;
import com.snailhd.entity.StockRealTime;
import com.snailhd.listener.StockRealTimeListener;
import com.snailhd.mapper.StockMapper;
import com.snailhd.util.StocklUtil;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.IJobHandler;
import com.xxl.job.core.handler.annotation.JobHandler;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * 维护实时数据到mongo
 * @author hd
 * @date 2019-11-23 11:20
 */

@Slf4j
@Component
@JobHandler(value="stockRealTimeDataMaintainSheduled")
public class StockRealTimeDataMaintainSheduled extends IJobHandler {

    @Resource
    CrawlerRealTimeStockDataExector crawlerRealTimeStockDataExector;

    @Resource
    StockRealTimeListener stockRealTimeListener;

    @Resource
    StockMapper stockMapper;

    @Override
    public ReturnT<String> execute(String s) throws Exception {
        log.info("定时爬取实时数据start");
        List<Stock> list = stockMapper.query(new QueryStockListDTO());
        List<StockRealTime> stockRealTimes = crawlerRealTimeStockDataExector.exec(StocklUtil.getSymbols(list));
        stockRealTimeListener.monitor(stockRealTimes);
        return ReturnT.SUCCESS;
    }

}
